package cn.kgc.controller;


import cn.kgc.service.TestService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/sentinel")
@Api(tags = "sentinel测试")

public class SentinelDemoApplication {


    @Resource
    private TestService testService;

    @GetMapping("/testA")
    public String testA(){
        return testService.common();
    }

    @GetMapping("/testB")
    public String testB(){
        return testService.common();
    }



    //blockHandlerClass为限流处理类，blockHandler为限流处理方法
    @GetMapping("/method1")
    @ApiOperation(value = "method测试1")
    @SentinelResource(value="m1",
            blockHandlerClass = SentinelBlockHandler.class,
            blockHandler = "methodBlockHandler")
    public  String method(){
        return "sentinel测试1";
    }


    //blockHandler为限流处理方法
    @GetMapping("/method2")
    @ApiOperation(value = "method测试2")
    @SentinelResource(value="m2", blockHandler = "methodBlockHandler")
    public  String method2(){
        return "sentinel测试2";
    }

}
